<%--
  Created by IntelliJ IDEA.
  User: 金
  Date: 2020/8/19/019
  Time: 9:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>购物车页面</title>

    <link href="${pageContext.request.contextPath}/front/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/front/basic/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/front/css/cartstyle.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/front/css/optstyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="${pageContext.request.contextPath}/front/js/jquery.js"></script>

</head>

<body>

<!--顶部导航条 -->
<div class="am-container header">
    <ul class="message-l">
        <div class="topMessage">
            <div class="menu-hd">
                <a href="login.html" target="_top" class="h">亲，请登录</a>
                <a href="register.html" target="_top">免费注册</a>
            </div>
        </div>
    </ul>
    <ul class="message-r">
        <div class="topMessage home">
            <div class="menu-hd"><a href="index.jsp" target="_top" class="h">商城首页</a></div>
        </div>
        <div class="topMessage my-shangcheng">
            <div class="menu-hd MyShangcheng"><a href="userInfo.html" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a></div>
        </div>
        <div class="topMessage mini-cart" id="topShop">
            <%--<div class="menu-hd"><a id="mc-menu-hd" href="shopcart.html" target="_top"><i class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum" class="h">0</strong></a></div>--%>
        </div>
        <div class="topMessage favorite">
            <div class="menu-hd"><a href="collection.html" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>
        </div>
    </ul>
</div>

<!--悬浮搜索框-->

<div class="nav white">
    <div class="logo"><img src="${pageContext.request.contextPath}/front/images/logo.png" /></div>
    <div class="logoBig">
        <li><a href="index.html"><img src="${pageContext.request.contextPath}/front/images/logobig.png" /></a></li>
    </div>

    <div class="search-bar pr">
        <a name="index_none_header_sysc" href="#"></a>
        <form>
            <input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索" autocomplete="off">
            <input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
        </form>
    </div>
</div>

<div class="clear"></div>

<!--购物车 -->
<div class="concent">
    <div id="cartTable">
        <div class="cart-table-th">
            <div class="wp">
                <div class="th th-chk">
                    <div id="J_SelectAll1" class="select-all J_SelectAll">

                    </div>
                </div>
                <div class="th th-item">
                    <div class="td-inner">商品信息</div>
                </div>
                <div class="th th-price">
                    <div class="td-inner">单价</div>
                </div>
                <div class="th th-amount">
                    <div class="td-inner">数量</div>
                </div>
                <div class="th th-sum">
                    <div class="td-inner">金额</div>
                </div>
                <div class="th th-op">
                    <div class="td-inner">操作</div>
                </div>
            </div>
        </div>
        <div class="clear"></div>

        <tr class="item-list">
            <div class="bundle  bundle-last ">
                <div class="bundle-hd">
                    <div class="bd-promos">
                        <div class="bd-has-promo">已享<span class="bd-has-promo-content">超值优惠</span>&nbsp;&nbsp;</div>
                        <div class="act-promo">
                            <a href="#" target="_blank">多买多送<span class="gt">&gt;&gt;</span></a>
                        </div>
                        <span class="list-change theme-login">编辑</span>
                    </div>
                </div>
                <div class="clear"></div>
                <%--显示订单--%>
                <div class="bundle-main">

                </div>
            </div>
        </tr>

    </div>
    <div class="clear"></div>

    <div class="float-bar-wrapper">
        <%--底部操作--%>
    </div>

    <div class="footer">
        <div class="footer-hd">
            <p>
                <a href="http://www.itcast.cn">传智播客</a>
                <b>|</b>
                <a href="javascript:void(0)">商城首页</a>
                <b>|</b>
                <a href="javascript:void(0)">支付宝</a>
                <b>|</b>
                <a href="javascript:void(0)">物流</a>
            </p>
        </div>
        <div class="footer-bd">
            <p>
                <a href="http://www.itcast.cn">关于黑马</a>
                <a href="javascript:void(0)">合作伙伴</a>
                <a href="javascript:void(0)">联系我们</a>
                <a href="javascript:void(0)">网站地图</a>
                <em>© 2015-2025 Hengwang.com 版权所有</em>
            </p>
        </div>
    </div>

</div>

<!--引导 -->
<div class="navCir">
    <li><a href="home.html"><i class="am-icon-home "></i>首页</a></li>
    <li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
    <li class="active"><a href="shopcart.html"><i class="am-icon-shopping-basket"></i>购物车</a></li>
    <li><a href="person/index.html"><i class="am-icon-user"></i>我的</a></li>
</div>
</body>
<script type="text/javascript">
    $(document).ready(function(){
        queryPr();
    });
</script>

<script type="text/javascript">
    function queryPr(){
        //购物车查询
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath }/ShoppingcartController/find",
            type:"GET",
            data:{userId:${frontUser.id}
            },
            dataType:"json",
            success:function(data){
                //显示订单
                var content = "";
                var totalcount = 0;
                var totalp = 0;
                $.each(data,function (index,obj) {
                    content += "<ul class=\"item-content clearfix\">\n" +
                        "                        <li class=\"td td-item\">\n" +
                        "                            <div class=\"item-pic\">\n" +
                        "                                <a href=\"#\" target=\"_blank\" data-title=\"图片\" class=\"J_MakePoint\" data-point=\"tbcart.8.12\">\n" +
                        "                                    <img src=\""+obj.img+"\" class=\"itempic J_ItemImg\"></a>\n" +
                        "                            </div>\n" +
                        "                            <div class=\"item-info\">\n" +
                        "                                <div class=\"item-basic-info\">\n" +
                        "                                    <a href=\"#\" target=\"_blank\" title=\"名字\" class=\"item-title J_MakePoint\" data-point=\"tbcart.8.11\">"+obj.goodsName+"</a>\n" +
                        "                                </div>\n" +
                        "                            </div>\n" +
                        "                        </li>\n" +
                        "                        <li class=\"td td-price\">\n" +
                        "                            <div class=\"item-price price-promo-promo\">\n" +
                        "                                <div class=\"price-content\">\n" +
                        "                                    <div class=\"price-line\">\n" +
                        "                                        <em class=\"price-original\">78.00</em>\n" +
                        "                                    </div>\n" +
                        "                                    <div class=\"price-line\">\n" +
                        "                                        <em class=\"J_Price price-now\" tabindex=\"0\">"+obj.price+"</em>\n" +
                        "                                    </div>\n" +
                        "                                </div>\n" +
                        "                            </div>\n" +
                        "                        </li>\n" +
                        "                        <li class=\"td td-amount\">\n" +
                        "                            <div class=\"amount-wrapper \">\n" +
                        "                                <div class=\"item-amount \">\n" +
                        "                                    <div class=\"sl\">\n" +
                        "                                        <input class=\"min am-btn\" name=\"\" type=\"button\" value=\"-\" onclick=\"downfun('"+obj.goodsId+"','"+obj.goodsCount+"')\"/>\n" +
                        "                                        <input class=\"text_box\" name=\"\" type=\"text\" value=\""+obj.goodsCount+"\" style=\"width:30px;\" />\n" +
                        "                                        <input class=\"add am-btn\" name=\"\" type=\"button\" value=\"+\" onclick=\"upfun('"+obj.goodsId+"','"+obj.goodsCount+"')\"/>\n" +
                        "                                    </div>\n" +
                        "                                </div>\n" +
                        "                            </div>\n" +
                        "                        </li>\n" +
                        "                        <li class=\"td td-sum\">\n" +
                        "                            <div class=\"td-inner\">\n" +
                        "                                <em tabindex=\"0\" class=\"J_ItemSum number\">"+obj.price*obj.goodsCount+"</em>\n" +
                        "                            </div>\n" +
                        "                        </li>\n" +
                        "                        <li class=\"td td-op\">\n" +
                        "                            <div class=\"td-inner\">\n" +
                        "                                <a title=\"移入收藏夹\" class=\"btn-fav\" href=\"#\">\n" +
                        "                                    移入收藏夹</a>\n" +
                        "                                <a href=\"javascript:;\" data-point-url=\"#\" class=\"delete\" onclick=\"delS('"+obj.goodsId+"')\">\n" +
                        "                                    删除</a>\n" +
                        "                            </div>\n" +
                        "                        </li>\n" +
                        "                    </ul>";
                    totalcount += obj.goodsCount;
                    totalp += obj.price*obj.goodsCount;
                })
                $(".bundle-main").html(content);
                var hh = "<div class=\"operations\">\n" +
                    "            <a href=\"#\" hidefocus=\"true\" class=\"deleteAll\" onclick=\"delA()\">全部删除</a>\n" +
                    "            <a href=\"#\" hidefocus=\"true\" class=\"J_BatchFav\">移入收藏夹</a>\n" +
                    "        </div>\n" +
                    "        <div class=\"float-bar-right\">\n" +
                    "            <div class=\"amount-sum\">\n" +
                    "                <span class=\"txt\">已选商品</span>\n" +
                    "                <em id=\"J_SelectedItemsCount\">"+totalcount+"</em><span class=\"txt\">件</span>\n" +
                    "                <div class=\"arrow-box\">\n" +
                    "                    <span class=\"selected-items-arrow\"></span>\n" +
                    "                    <span class=\"arrow\"></span>\n" +
                    "                </div>\n" +
                    "            </div>\n" +
                    "            <div class=\"price-sum\">\n" +
                    "                <span class=\"txt\">合计:</span>\n" +
                    "                <strong class=\"price\">¥<em id=\"J_Total\">"+totalp+"</em></strong>\n" +
                    "            </div>\n" +
                    "            <div class=\"btn-area\">\n" +
                    "                <a href=\"pay.jsp\" id=\"J_Go\" class=\"submit-btn submit-btn-disabled\" aria-label=\"请注意如果没有选择宝贝，将无法结算\">\n" +
                    "                    <span>结&nbsp;算</span></a>\n" +
                    "            </div>\n" +
                    "        </div>";
                $(".float-bar-wrapper").html(hh);
                var cc="<div class=\"menu-hd\"><a id=\"mc-menu-hd\" href=\"front/shopcart.jsp\" target=\"_top\"><i class=\"am-icon-shopping-cart  am-icon-fw\"></i><span>购物车</span><strong id=\"J_MiniCartNum\" class=\"h\">￥"+totalp+"</strong></a></div>";
                $("#topShop").html(cc);
            },
            error :function(xhr,status,error){
                alert("ajax异步请求失败");
            }
        });
    }

    /*数量加*/
    function upfun(goodid,goodCount) {
        var count = 0;
        count = parseFloat(goodCount) + 1;
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath }/ShoppingcartController/update",
            type:"POST",
            data:{userId:${frontUser.id},
                goodsId:goodid,
                goodsCount:count
            },
            dataType:"text",
            success:function(data){
                queryPr();
            }
        });
    }

    /*数量减*/
    function downfun(goodid,goodCount) {
        var count = 0;
        if(goodCount == 1){
            count = goodCount;
        }else {
            count = goodCount-1;
        }
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath }/ShoppingcartController/update",
            type:"POST",
            data:{userId:${frontUser.id},
                goodsId:goodid,
                goodsCount:count
            },
            dataType:"text",
            success:function(data){
                queryPr();
            }
        });
    }

    /*删除单个*/
    function delS(goodid) {
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath }/ShoppingcartController/delS",
            type:"POST",
            data:{userId:${frontUser.id},
                goodsId:goodid,
            },
            dataType:"text",
            success:function(data){
                queryPr();
            }
        });
    }

    /*删除所有*/
    function delA() {
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath }/ShoppingcartController/delA",
            type:"POST",
            data:{userId:${frontUser.id},
            },
            dataType:"text",
            success:function(data){
                queryPr();
            }
        });
    }
</script>
</html>
